package com.baishancloud.log

import cn.hutool.json.JSONUtil
import com.baishancloud.log
import com.baishancloud.log.quality.pojo.{RateResult, RateResultFields, Tags}
import org.junit.Test

import scala.collection.mutable.ListBuffer

class AppTestS {

  /**
   * 判断网络类型
   *
   * @param network 网络类型id
   * @return
   */
  private def netTypeJudge(network: Int): String = {
    network match {
      case 0 => "UNKNOWN"
      case 1 => "WIFI"
      case 2 => "CELLULAR"
      case 3 => "OFFLINE"
      case 4 => "OTHERNET"
      case 5 => "ETHERNET"
      case _ => ""
    }
  }

  @Test
  def test1(): Unit = {
    val s: String = "http://d1--cn-gotcha06.bilivideo.com/live-bvc/526243/live_473837611_14189661_minihevc.flv?expires=1636369377&len=0&oi=2090915534&pt=android&qn=0&trid=1000874133064ee6407ea50fedd4db13f4cd&sigparams=cdn,expires,len,oi,pt,qn,trid&cdn=cn-gotcha06&sign=94ceafa0492dcf7d3f4ce831b9a998a1&p2p_type=0&src=40&sl=3&flowtype=1&source=batch&order=1&machinezone=ylf&sk=2935686d6cb9146c7a6a6a0b4e120e250342be3df4dc8310261aab0ce9e21e44"
    val split: Array[String] = s.split("/")
    println(split.length)
    println(split(2))
  }


  /**
   * 按照升序排序数字集合，然后取特定位置的数字
   *
   * @param list    数字集合
   * @param percent 百分位，整数，0~1
   * @return 如果集合为空，返回0；如果percent为0，返回集合排序后的第一个元素；如果percent为1，返回集合排序后的最后一个元素
   */
  private def percentValue(list: ListBuffer[Double], percent: Double): Double = {
    if (list == null || list.isEmpty) return 0
    val array: Array[Double] = list.sorted(Ordering.Double).toArray
    println(array.mkString("", ",", ""))
    if (percent == 0) {
      array(0)
    } else if (percent == 1) {
      array(array.length)
    } else {
      array((array.length * percent).toInt)
    }
  }

  @Test
  def test3(): Unit = {
    val list = ListBuffer[Double]()
    list.+=(1)
    list.+=(4)
    list.+=(4)
    list.+=(4)
    list.+=(6)
    list.+=(5)
    list.+=(3)
    list.+=(3)
    list.+=(1)
    list.+=(1)
    println(list.toString)
    println(list.sorted(Ordering.Double).toArray.mkString(","))
  }

  @Test
  def test4(): Unit = {
    val d = 1.123456789
    println(d.formatted("%.2f").toDouble)
    println(d.formatted("%.4f").toDouble)
    println(d.formatted("%.5f").toDouble)
    println(d.formatted("%.6f").toDouble)
  }


  @Test
  def test6(): Unit = {
    val r = RateResult(1234567890L, 300, "bigdata_bilibili_quality", 0.1, "endpoint123", Tags("5m", "android", "live", "mobile", "bilibili.com", "北京", "联通", "UNKNOW", "cache1", log.quality.vvCardFrameRate), RateResultFields(12345.0, 34567.0))
    println(JSONUtil.toJsonStr(r))
  }


}
